package com.linked.basemanage.permissioncontrol.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.linked.basemanage.permissioncontrol.bean.po.SystemInfoPO;
import com.linked.basemanage.permissioncontrol.mapper.ISystemInfoMapper;
import com.linked.basemanage.permissioncontrol.service.ISystemInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
 * @author :dbq
 * @date : 2023/2/22 14:53
 * @description : desc
 */
@Service
@Slf4j
public class SystemInfoServiceImpl implements ISystemInfoService {

    private final ISystemInfoMapper systemInfoMapper;

    private final ObjectMapper mapper;

    @Autowired
    public SystemInfoServiceImpl(ISystemInfoMapper systemInfoMapper, ObjectMapper mapper) {
        this.systemInfoMapper = systemInfoMapper;
        this.mapper = mapper;
    }

    @Override
    public boolean addSystem(SystemInfoPO param) throws Exception {
        return systemInfoMapper.insert(param) > 0;
    }

    @Override
    public List<SystemInfoPO> querySystemInfoList(@RequestBody SystemInfoPO param) throws Exception {
        QueryWrapper<SystemInfoPO> wrapper = new QueryWrapper<>();
        wrapper.eq("data_status", 1);
        if (!StringUtils.isEmpty(param.getSystemKey())) {
            wrapper.eq("system_key", param.getSystemKey());
        }
        return systemInfoMapper.selectList(wrapper);
    }
}
